using Batman.Identity.Startups;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using NLog.Web;
using System.IO;
using System.Net.Http;
using Xunit.Abstractions;

namespace Batman.Identity.Test
{
    public class UnitTestBase
    {
        protected ITestOutputHelper _testOutputHelper;

        protected HttpClient httpClient;

        public UnitTestBase(ITestOutputHelper testOutputHelper)
        {
            var webHostBuilder = WebHost.CreateDefaultBuilder();
            webHostBuilder = webHostBuilder.ConfigureAppConfiguration((hostingContext, builder) =>
            {
                var location = typeof(UnitTestBase).Assembly.Location;
                var basePath = new FileInfo(location).Directory.Parent.Parent.Parent.Parent.Parent.FullName;
                var identityBasePath = Path.Combine(basePath, "src", "Batman.Identity");
                builder.SetBasePath(identityBasePath).AddJsonFile("appsettings.json");
            });
            webHostBuilder = webHostBuilder.UseStartup<Startup>();
            var server = new TestServer(webHostBuilder);
            httpClient = server.CreateClient();

            _testOutputHelper = testOutputHelper;
        }
    }
}
